package com.xscha.tableforge.jooq.tables;

import org.jooq.*;
import org.jooq.Record;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.TableImpl;

import java.time.LocalDateTime;

/**
 * 字段元数据表
 * 用于存储数据表的字段信息，包括字段名称、类型、属性等
 */
public class FieldMetaTable extends TableImpl<Record> {

    private static final long serialVersionUID = -1L;

    public static final FieldMetaTable FIELD_META = new FieldMetaTable();

    /** 字段ID */
    public final TableField<Record, String> ID = createField(DSL.name("id"), SQLDataType.VARCHAR.nullable(false), this);
    /** 字段名称 */
    public final TableField<Record, String> NAME = createField(DSL.name("name"), SQLDataType.VARCHAR.nullable(false), this);
    /** 字段描述 */
    public final TableField<Record, String> DESCRIPTION = createField(DSL.name("description"), SQLDataType.VARCHAR, this);
    /** 字段选项(JSON格式) */
    public final TableField<Record, String> OPTIONS = createField(DSL.name("options"), SQLDataType.VARCHAR, this);
    /** 字段类型 */
    public final TableField<Record, String> TYPE = createField(DSL.name("type"), SQLDataType.VARCHAR.nullable(false), this);
    /** 单元格值类型 */
    public final TableField<Record, String> CELL_VALUE_TYPE = createField(DSL.name("cell_value_type"), SQLDataType.VARCHAR.nullable(false), this);
    /** 是否多个单元格值 */
    public final TableField<Record, Boolean> IS_MULTIPLE_CELL_VALUE = createField(DSL.name("is_multiple_cell_value"), SQLDataType.BOOLEAN, this);
    /** 数据库字段类型 */
    public final TableField<Record, String> DB_FIELD_TYPE = createField(DSL.name("db_field_type"), SQLDataType.VARCHAR.nullable(false), this);
    /** 数据库字段名称 */
    public final TableField<Record, String> DB_FIELD_NAME = createField(DSL.name("db_field_name"), SQLDataType.VARCHAR.nullable(false), this);
    /** 是否必填 */
    public final TableField<Record, Boolean> NOT_NULL = createField(DSL.name("not_null"), SQLDataType.BOOLEAN, this);
    /** 是否唯一 */
    public final TableField<Record, Boolean> IS_UNIQUE = createField(DSL.name("is_unique"), SQLDataType.BOOLEAN, this);
    /** 是否主键 */
    public final TableField<Record, Boolean> IS_PRIMARY = createField(DSL.name("is_primary"), SQLDataType.BOOLEAN, this);
    /** 是否计算 */
    public final TableField<Record, Boolean> IS_COMPUTED = createField(DSL.name("is_computed"), SQLDataType.BOOLEAN, this);
    /** 是否查找 */
    public final TableField<Record, Boolean> IS_LOOKUP = createField(DSL.name("is_lookup"), SQLDataType.BOOLEAN, this);
    /** 是否挂起 */
    public final TableField<Record, Boolean> IS_PENDING = createField(DSL.name("is_pending"), SQLDataType.BOOLEAN, this);
    /** 是否有错误 */
    public final TableField<Record, Boolean> HAS_ERROR = createField(DSL.name("has_error"), SQLDataType.BOOLEAN, this);
    /** 查找链接字段ID */
    public final TableField<Record, String> LOOKUP_LINKED_FIELD_ID = createField(DSL.name("lookup_linked_field_id"), SQLDataType.VARCHAR, this);
    /** 查找选项 */
    public final TableField<Record, String> LOOKUP_OPTIONS = createField(DSL.name("lookup_options"), SQLDataType.VARCHAR, this);
    /** 所属表ID */
    public final TableField<Record, String> TABLE_ID = createField(DSL.name("table_id"), SQLDataType.VARCHAR.nullable(false), this);
    /** 版本 */
    public final TableField<Record, Integer> VERSION = createField(DSL.name("version"), SQLDataType.INTEGER.nullable(false), this);
    /** 显示顺序 */
    public final TableField<Record, Double> DISPLAY_ORDER = createField(DSL.name("display_order"), SQLDataType.DOUBLE.nullable(false), this);
    /** 创建时间 */
    public final TableField<Record, LocalDateTime> CREATED_TIME = createField(DSL.name("created_time"), SQLDataType.LOCALDATETIME(3).nullable(false).defaultValue(DSL.field("CURRENT_TIMESTAMP", SQLDataType.LOCALDATETIME)), this);
    /** 最后修改时间 */
    public final TableField<Record, LocalDateTime> LAST_MODIFIED_TIME = createField(DSL.name("last_modified_time"), SQLDataType.LOCALDATETIME(3), this);
    /** 删除时间 */
    public final TableField<Record, LocalDateTime> DELETED_TIME = createField(DSL.name("deleted_time"), SQLDataType.LOCALDATETIME(3), this);
    /** 创建人 */
    public final TableField<Record, String> CREATED_BY = createField(DSL.name("created_by"), SQLDataType.VARCHAR.nullable(false), this);
    /** 最后修改人 */
    public final TableField<Record, String> LAST_MODIFIED_BY = createField(DSL.name("last_modified_by"), SQLDataType.VARCHAR, this);

    private FieldMetaTable() {
        super(DSL.name("field_meta"));
    }

    @Override
    public Schema getSchema() {
        return DSL.schema(DSL.name("public"));
    }

    @Override
    public UniqueKey<Record> getPrimaryKey() {
        return Keys.FIELD_META_PKEY;
    }

    @Override
    public FieldMetaTable as(String alias) {
        return new FieldMetaTable().as(alias);
    }

    @Override
    public FieldMetaTable as(Name alias) {
        return new FieldMetaTable().as(alias);
    }
} 